<template>
  <view class="content">
    <image @click="toLogin" class="logo" src="/static/logo.png" />
    <view class="text-area" @click="toChange">
      <text class="title">{{ title }}</text>
    </view>
    <uni-icons type="contact" size="30"></uni-icons>
    <uni-calendar
      :insert="true"
      :lunar="true"
      :start-date="'2019-3-2'"
      :end-date="'2019-5-20'"
    />
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useStore } from '@/store/index'
import { login, count } from '@/api/member'
import { onLoad } from '@dcloudio/uni-app'

const store = useStore()
const title = ref<string>(store.title)

// 请求登录接口
const toLogin = async () => {
  console.log('登录中 --- ')
  uni.login({
    provider: 'weixin', // 使用微信登录
    success: function (loginRes) {
      console.log('loginRes.authResult --- ', loginRes)
    }
  })
}

const toChange = async () => {
  console.log('点击了 --- ')
  store.increment()
  title.value = store.title
  // await toLogin()
  getCount()
}

const getCount = async () => {
  const { errcode = '', errmsg = '', result } = await count()
  console.log(errcode, errmsg, result)
}

onLoad(() => {
  getCount()
})
</script>

<style>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 200rpx;
  width: 200rpx;
  margin-top: 200rpx;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 50rpx;
}

.text-area {
  display: flex;
  justify-content: center;
}

.title {
  font-size: 36rpx;
  color: #8f8f94;
}
</style>
